#include "SmartMenu.h"


// 在主菜单中添加子动作项，支持两种方式创建：一种是通过传入动作项对象创建，一种是传入相关属性参数创建
USmartAction* USmartMenu::AddAction(USmartAction* InAction, const FString& InName, const FString& InCommand, const FString& InDescription) {
	if (InAction == nullptr) {
		InAction = NewObject<USmartAction>();
		InAction->Name = InName;
		InAction->Command = InCommand;
		InAction->Description = InDescription;
	}
	Items.Add(InAction);
	return InAction;
}

USmartAction* USmartMenu::InsertAction(int32 Index, USmartAction* InAction, const FString& InName,
	const FString& InCommand, const FString& InDescription)
{
	if (InAction == nullptr) {
		InAction = NewObject<USmartAction>();
		InAction->Name = InName;
		InAction->Command = InCommand;
		InAction->Description = InDescription;
	}
	// Items.Add(InAction);
	Items.Insert(InAction, Index);
	return InAction;
}

int32 USmartMenu::ActionCount()
{
	return Items.Num();
}

// 在主菜单中添加子菜单，支持两种方式创建：一种是通过传入菜单对象创建，一种是传入相关属性参数创建
USmartMenu* USmartMenu::AddMenu(USmartMenu* InMenu, const FString& InName, const FString& InDescription) {
	if (InMenu == nullptr) {
		InMenu = NewObject<USmartMenu>();
		InMenu->Name = InName;
		InMenu->Description = InDescription;
	}
	Items.Add(InMenu);
	return InMenu;
}

// 在主菜单中添加分割线，支持两种方式创建：一种是通过传入分割线对象创建，一种是空参创建
void USmartMenu::AddSeparator(USmartSeparator* InSeparator) {
	if (InSeparator == nullptr) {
		InSeparator = NewObject<USmartSeparator>();
	}
	Items.Add(InSeparator);
};

// 在主菜单中添加起始段，支持两种方式创建：一种是通过传入起始段对象创建，一种是传入相关属性参数创建
USmartBeginSection* USmartMenu::AddBeginSection(USmartBeginSection* InBeginSection, const FString& InName) {
	if (InBeginSection == nullptr) {
		InBeginSection = NewObject<USmartBeginSection>();
		InBeginSection->Name = InName;
	}
	Items.Add(InBeginSection);
	return InBeginSection;
};

// 在主菜单中添加结束段，支持两种方式创建：一种是通过传入结束段对象创建，一种是空参创建
void USmartMenu::AddEndSection(USmartEndSection* InEndSection) {
	if (InEndSection == nullptr) {
		InEndSection = NewObject<USmartEndSection>();
	}
	Items.Add(InEndSection);
};